//
//  ViewController6.m
//  30303
//
//  Created by student on 16/3/18.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController6.h"

@interface ViewController6 ()
@property (weak, nonatomic) IBOutlet UIImageView *imageview;

@end

@implementation ViewController6

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UISwipeGestureRecognizer *leftg=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipe:)];
    leftg.direction=UISwipeGestureRecognizerDirectionLeft;
     UISwipeGestureRecognizer *rightg=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipe:)];
    rightg.direction=UISwipeGestureRecognizerDirectionRight;
    [self.view addGestureRecognizer:leftg];
    [self.view addGestureRecognizer:rightg];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
-(void)swipe:(UISwipeGestureRecognizer *)g
{
    CATransition *anim=[CATransition animation];
    anim.duration=1;
    anim.type=@"fade";
    
    static int i=1;
    if(g.direction==UISwipeGestureRecognizerDirectionLeft)
    {
        i--;
        if(i<=0)
        {
            i=5;
        }
        anim.subtype=kCATransitionFromRight;
    }
    else
    {
        i++;
        if(i>5)
        {
            i=1;
        }
        anim.subtype=kCATransitionFromLeft;
    }
    self.imageview.image=[UIImage imageNamed:[NSString stringWithFormat:@"bike%i.jpg",i]];
    [self.imageview.layer addAnimation:anim forKey:nil];
    
}
@end
